<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="result"></div>
    <script>
        const result = document.getElementById('result')
        function sendAjax(url) {
            return new Promise((resolve, reject) => {
                const xmr = new XMLHttpRequest()
                xmr.open('GET', url, true)
                xmr.send()
                xmr.onreadystatechange = function () {
                    if (xmr.readyState === 4) {
                        if (xmr.status >= 200 && xmr.status < 300) {
                            console.log(xmr.response)
                            resolve(xmr.response)
                        } else {
                            console.log('出错了')
                            reject('出错了')
                        }
                    }
                }
            })
        }
        sendAjax('http://127.0.0.1:8000/serve?a=1&&b=2').then(res => {
            result.innerHTML = res
            console.log(res)
        }, err => {
            console.log(err)
        })
    </script>
</body>

</html>